/*
 * @Author: 陈明烽
 * @Date: 2021-04-06 13:31:58
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-04-21 16:16:46
 * @FilePath: \evdata\src\Icon\index.tsx
 * @Description: Icon
 */
import React from 'react';
import Classnames from 'classnames';
import { createFromIconfontCN } from '@ant-design/icons';
import { IconFontProps } from '@ant-design/icons/lib/components/IconFont';
// import './font-awesome-4.7.0/css/font-awesome.min.css';
import 'font-awesome/css/font-awesome.min.css';
type ThemeType = 'success' | 'default' | 'danger' | 'warning';

const EvdataIcon = createFromIconfontCN({
  scriptUrl: '//at.alicdn.com/t/font_2467581_jkzk24q6iws.js', // 在 iconfont.cn 上生成
});

const AndtIcon = createFromIconfontCN({
  scriptUrl: '//at.alicdn.com/t/font_2048740_5t8xwxanw13.js', // 在 iconfont.cn 上生成
});

interface IconProps extends IconFontProps {
  className?: string;
  temes?: ThemeType;
}

const Icon: React.FC<IconProps> = props => {
  const { type, temes, className, ...resetProps } = props;

  const isfa = type.indexOf('fa') === 0;
  const isAntd = type.indexOf('antd') === 0;
  const isEvdata = type.indexOf('evdata') === 0;
  const classes = Classnames('c_icon', className, { [`icon-${temes}`]: temes });
  const faClasses = Classnames('c_icon', 'fa', className, type);

  return (
    <>
      {isfa && <i className={faClasses}></i>}
      {isAntd && <AndtIcon className={classes} type={type} {...resetProps} />}
      {isEvdata && (
        <EvdataIcon className={classes} type={type} {...resetProps} />
      )}
    </>
  );
};
Icon.defaultProps = {
  temes: 'default',
};
export default Icon;
